package com.example.ex3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class ScoreActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score);

        Button b1 = findViewById(R.id.b1);
        Button b2 = findViewById(R.id.b2);
        Button b3 = findViewById(R.id.b3);
        Button b4 = findViewById(R.id.b4);
        Button b5 = findViewById(R.id.b5);
        Button b6 = findViewById(R.id.b6);
        Button b7 = findViewById(R.id.b7);
        b1.setOnClickListener(this::click1);
        b2.setOnClickListener(this::click2);
        b3.setOnClickListener(this::click3);
        b4.setOnClickListener(this::click4);
        b5.setOnClickListener(this::click1);
        b6.setOnClickListener(this::click2);
        b7.setOnClickListener(this::click3);
    }

    public void click1(View btn){
        Log.i("main","click1:1");
        TextView text = findViewById(R.id.text2);
        TextView text2 = findViewById(R.id.text4);

        Log.i("main","click1:2");
        if (btn.getId()==R.id.b5){
            int a = Integer.parseInt(text.getText().toString());
            int b =a+3;
            String c = String.valueOf(b);
            text.setText(c);
        }else{
            int a = Integer.parseInt(text2.getText().toString());
            int b =a+3;
            String c = String.valueOf(b);
            text2.setText(c);
        }
    }

    public void click2(View btn){
        Log.i("main","click2:1");
        TextView text = findViewById(R.id.text2);
        TextView text2 = findViewById(R.id.text4);

        Log.i("main","click2:2");
        if (btn.getId()==R.id.b6){
            int a = Integer.parseInt(text.getText().toString());
            int b =a+2;
            String c = String.valueOf(b);
            text.setText(c);
        }else{
            int a = Integer.parseInt(text2.getText().toString());
            int b =a+2;
            String c = String.valueOf(b);
            text2.setText(c);
        }
    }

    public void click3(View btn){
        Log.i("main","click1:1");
        TextView text = findViewById(R.id.text2);
        TextView text2 = findViewById(R.id.text4);

        Log.i("main","click1:2");
        if (btn.getId()==R.id.b7){
            int a = Integer.parseInt(text.getText().toString());
            int b =a+1;
            String c = String.valueOf(b);
            text.setText(c);
        }else{
            int a = Integer.parseInt(text2.getText().toString());
            int b =a+1;
            String c = String.valueOf(b);
            text2.setText(c);
        }
    }

    public void click4(View v){
        Log.i("main","click1:1");
        TextView text1 = findViewById(R.id.text2);
        TextView text2 = findViewById(R.id.text4);

        Log.i("main","click1:2");
        text1.setText("0");
        text2.setText("0");
    }
}